//
// Created by xbm on 23-3-10.
//

#ifndef WEBSERVER_DISPATCHER_H
#define WEBSERVER_DISPATCHER_H
#include <functional>
#include <unordered_map>
#include <memory>
#include "nonCopyable.h"
#include "event.h"

using namespace std;

namespace event{
class Dispatcher : util::NonCopyable {
public:
    using HandlerType = function<void(shared_ptr < Event > )>;

    static Dispatcher &getInstance() {
        static Dispatcher dp;
        return dp;
    }

    void registerHandler(int, HandlerType);

    void dispatch(const shared_ptr<Event> &);

private:
    unordered_map<int, HandlerType> registered;
};
}
#endif //WEBSERVER_DISPATCHER_H
